<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>01.class样式</title>
        <!-- 引入Vue -->
        <style>
			.basic{
				width: 400px;
				height: 100px;
				border: 1px solid black;
			}
			
			/* 三种心情，三选一 */
			.happy{
				border: 4px solid red;;
				background-color: rgba(255, 255, 0, 0.644);
				background: linear-gradient(30deg,yellow,pink,orange,yellow);
			}
			.sad{
				border: 4px dashed black;
				background-color: gray;
			}
			.normal{
				border: 4px solid deepskyblue;
				background-color: skyblue;
			}
			
			/* 三个样式，随意选择，可以同时存在 */
			.atguigu1{
				background-color: yellowgreen;
			}
			.atguigu2{
				font-size: 30px;
				text-shadow:2px 2px 10px red;
			}
			.atguigu3{
				border-radius: 20px;
			}
           </style>
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="demo">
            <!-- 直接添加属性 -->
            <div class="basic" :class="str">山美眉</div>
            <button @click="change">点击切换心情</button>
            <br>
            <!-- 添加对象 -->
            <div class="basic" :class="obj">山美眉</div>
            <button @click = "obj.atguigu1 = !obj.atguigu1">点击添加or取消atguigu1</button>
            <button @click = "obj.atguigu2 = !obj.atguigu2">点击添加or取消atguigu2</button>
            <button @click = "obj.atguigu3 = !obj.atguigu3">点击添加or取消atguigu3</button>
            <!-- 数组的方式 -->
            <div class="basic" :class="arr">山美眉</div>
            <input type="text"  @keyup.enter = "changeClassName">
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        new Vue({
            el:'#demo',
            data:{
                str:'happy',
                obj:{
                    atguigu1:true,
                    atguigu2:true,
                    atguigu3:true
                },
                arr:[]
            },
            methods:{
                change(){
                    const arr =['happy','sad','normal'];
                    let index =Math.floor(Math.random()*3);
                    console.log(index);
                    this.str = arr[index];
                },
                changeClassName(event){
                    let val = event.target.value;
                    this.arr.push(val)
                }
            }
            
        

        })
    </script>
</html>